package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC2079 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int wateringPlants(int[] plants, int capacity) {
            int ans = 0, curLeftWater = capacity;
            for (int i = 0; i < plants.length; i++) {
                if (curLeftWater < plants[i]) {
                    ans += 2 * i + 1;
                    curLeftWater = capacity - plants[i];
                } else {
                    curLeftWater -= plants[i];
                    ans++;
                }
            }

            return ans;
        }
    }

    public void run() {
        System.out.println(new Solution().wateringPlants(InputUtil.toIntegerArray("[2,2,3,3]"), 5));
        System.out.println(new Solution().wateringPlants(InputUtil.toIntegerArray("[1,1,1,4,2,3]"), 4));
        System.out.println(new Solution().wateringPlants(InputUtil.toIntegerArray("[7,7,7,7,7,7,7]"), 8));
    }

    public static void main(String[] args) throws Exception {
        LC2079 an = new LC2079();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
